//
//  YDTransactionDetailController.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/10.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDTransactionDetailController.h"
#import "YDTransactionDetailTableHeaderView.h"
#import "YDTransactionDetailTableCell.h"
#import "YDPositionModel.h"

@interface YDTransactionDetailController ()<UITableViewDelegate , UITableViewDataSource>

//tableView
@property (nonatomic , weak) UITableView *tableView;

@end

@implementation YDTransactionDetailController
- (void)viewDidLoad
{
    [super viewDidLoad];
//    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = NumberColor(247, 247, 247);
    self.title = @"交易详情";
    [self tableView];
    
}
/*******tableView********/
-(UITableView *)tableView
{
    if (_tableView == nil) {
        CGFloat safeH = isPhoneX ? 83 : 49;
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, LKScreenW, LKScreenH - safeH) style:UITableViewStyleGrouped];
        [self.view addSubview:tableView];
        tableView.backgroundColor = NumberColor(247, 247, 247);
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.estimatedRowHeight = 0;
        tableView.estimatedSectionFooterHeight = 0;
        tableView.estimatedSectionHeaderHeight = 0;
        if (isIos11) {
            tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
                }
        _tableView = tableView;
    }
    return _tableView;
}


/******************UITableViewDelegate , UITableViewDataSource************/
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 8;
    }else if (section == 1){
        return 3;
    }else if (section == 2){
        return 2;
    }else{
        return 3;
    }
}
//行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return isPhoneX ? rateX812(40) : rate750(40);
}
//顶部高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return isPhoneX ? rateX812(50) : rate750(50);
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return isPhoneX ? rateX812(10) : rate750(10);
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YDTransactionDetailTableCell *cell = [YDTransactionDetailTableCell cellWithTableView:tableView];

    if (indexPath.section == 0) {//第1组
        if (indexPath.item == 0) {
            cell.category1.text = @"股票名称";
            cell.contentRight.text = self.model.stockName;
            cell.contentRight.textColor = [UIColor colorWithHexString:dark];
        }else if (indexPath.item == 1){
            cell.category1.text = @"交易本金";
            cell.contentRight.text = self.model.pzReserveFund;
            cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
        }else if (indexPath.item == 2){
            cell.category1.text = @"交易数量";
            cell.contentRight.text = self.model.pzNumberOfStrand;
            cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
        }else if (indexPath.item == 3){
            cell.category1.text = @"买入价格";
            cell.contentRight.text = [NSString stringWithFormat:@"%@元/股",self.model.pzBuyingPrice];
            cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
        }else if (indexPath.item == 4){
            cell.category1.text = @"买入时间";
            cell.contentRight.text = [NSString stringWithFormat:@"%@ %@",self.model.buyYearStr , self.model.buyHourStr];
            cell.contentRight.textColor = [UIColor colorWithHexString:dark];
        }else if (indexPath.item == 5){
            cell.category1.text = @"卖出价格";
            cell.contentRight.text = [NSString stringWithFormat:@"%@元/股",self.model.pzSellingPrice];
            cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
        }else if (indexPath.item == 6){
            cell.category1.text = @"备注";
            cell.contentRight.text = self.model.windControlString;
            cell.contentRight.textColor = [UIColor colorWithHexString:dark];
        }else if (indexPath.item == 7){
            cell.category1.text = @"卖出时间";
            cell.contentRight.text = [NSString stringWithFormat:@"%@ %@",self.model.saleYearStr , self.model.saleHourStr];
            cell.contentRight.textColor = [UIColor colorWithHexString:dark];
        }
    }else if (indexPath.section == 1){//第2组
        if (indexPath.item == 0) {
            cell.category1.text = @"信息服务费";
            cell.contentRight.text = [NSString stringWithFormat:@"%@",self.model.pzServiceFee];
            cell.contentRight.textColor = [UIColor colorWithHexString:leafyGreen];
        }else if (indexPath.item == 1){
            cell.category1.text = @"递延次数";
            cell.contentRight.text = [NSString stringWithFormat:@"%zd次" , self.model.deferredDays];
            cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
        }else if (indexPath.item == 2){
            cell.category1.text = @"递延费用";
            cell.contentRight.text = [NSString stringWithFormat:@"%@" , self.model.pzDeferredCharges];
            cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
        }
    }else if (indexPath.section == 2){//第3组
        //        if (indexPath.item == 0) {
        //            cell.category1.text = @"冻结";
        //            cell.contentRight.text = self.model.pzReserveFund;
        //            cell.contentRight.textColor = [UIColor colorWithHexString:leafyGreen];
        //        }else if (indexPath.item == 1){
        //            cell.category1.text = @"扣减";
        //            cell.contentRight.text = self.model.detailDeduction;
        //            cell.contentRight.textColor = [UIColor colorWithHexString:leafyGreen];
        //        }else if (indexPath.item == 2){
        //            cell.category1.text = @"解冻";
        //            cell.contentRight.text = self.model.detailThaw;
        //            cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
        //        }
        if (indexPath.item == 0) {
            cell.category1.text = @"冻结";
            cell.contentRight.text = self.model.pzReserveFund;
            cell.contentRight.textColor = [UIColor colorWithHexString:leafyGreen];
        }else if (indexPath.item == 1){
            cell.category1.text = @"解冻";
            cell.contentRight.text = self.model.detailThaw;
            cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
        }
        
    }else{//第4组
        if (self.model.isSuccess) {//pzServiceFee;pzDeferredCharges
            if (indexPath.item == 0) {
                cell.category1.text = @"方案状态";
                cell.contentRight.text = @"已结算";
                cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
            }else if (indexPath.item == 1){
                cell.category1.text = @"交易盈亏";
                cell.contentRight.text = self.model.pzProfitOrLoss;
                cell.contentRight.textColor = [self.model.profitOrLoss floatValue] >=0 ? [UIColor colorWithHexString:paleRed] :[UIColor colorWithHexString:leafyGreen];
                
            }else if (indexPath.item == 2){
                cell.category1.text = @"盈利分配";
                cell.contentRight.text = self.model.pzPublisherProfitOrLoss;
                cell.contentRight.textColor = [self.model.publisherProfitOrLoss floatValue] >=0 ? [UIColor colorWithHexString:paleRed] :[UIColor colorWithHexString:leafyGreen];
            }
        }else{
            if (indexPath.item == 0) {
                cell.category1.text = @"方案状态";
                cell.contentRight.text = @"已退费";
                cell.contentRight.textColor = [UIColor colorWithHexString:paleRed];
            }else if (indexPath.item == 1){
                cell.category1.text = @"服务费";
                cell.contentRight.text = self.model.pzServiceFee;
                cell.contentRight.textColor = [self.model.pzServiceFee floatValue] >=0 ? [UIColor colorWithHexString:paleRed] :[UIColor colorWithHexString:leafyGreen];
                
            }else if (indexPath.item == 2){
                cell.category1.text = @"递延费";
                cell.contentRight.text = self.model.pzDeferredFee;
                cell.contentRight.textColor = [self.model.pzDeferredFee floatValue] >=0 ? [UIColor colorWithHexString:paleRed] :[UIColor colorWithHexString:leafyGreen];
            }
        }
        
    }
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    YDTransactionDetailTableHeaderView *headerView = [YDTransactionDetailTableHeaderView headerViewWithTableView:tableView];
    
    if (section == 0) {
        headerView.cateString = @"交易明细";
    }else if (section == 1){
        headerView.cateString = @"交易综合费";
    }else if (section == 2){
        headerView.cateString = @"履约保证金";
    }else{
        headerView.cateString = @"交易盈余分配";
    }
    return headerView;
}

@end
